import { cloneDeep } from 'lodash-es'
export const poinDeptDataFormat = (poinList) => {
  const deptNode = {
    id: '0',
    parentId: '0',
    name: '',
    icon: null,
    children: null,
  }
  const tempArray = []
  for (const item of poinList) {
    const newNode = cloneDeep(deptNode)
    newNode.id = item.id
    item.pid === -1 ? newNode.parentId = '0' : newNode.parentId = item.pid
    newNode.name = item.text
    tempArray.push(newNode)
  }
  const deptList = []
  for (const item of tempArray) {
    if (item.parentId === '0') {
      deptList.push(item)
    } else {
      const parentNode = tempArray.find(element => element.id === item.parentId)
      parentNode.children ? parentNode.children = [...parentNode.children, item] : parentNode.children = [item] 
    }
  }
  return deptList
}
export const poinAllDeptDataFormat = (poinList) => {
  console.log(poinList, 'poinList')
  const deptNode = {
    id: '0',
    parentId: '0',
    name: '',
    children: null,
  }
  const tempArray = []
  for (const item of poinList) {
    const newNode = cloneDeep(deptNode)
    newNode.id = item.id
    item.pid === -1 ? newNode.parentId = '0' : newNode.parentId = item.pid
    newNode.name = item.text
    tempArray.push(newNode)
  }
  console.log(tempArray, 'tempArray')
  const deptList = []
  for (const item of tempArray) {
    if (item.parentId === '0') {
      deptList.push(item)
    } else {
      const parentNode = tempArray.find(element => element.id === item.parentId)
      parentNode.children ? parentNode.children = [...parentNode.children, item] : parentNode.children = [item]
      
    }
  }
  console.log(deptList, 'deptList')
  return deptList
}